<!DOCTYPE html>
<html lang="en">
<head>
    <?php 
	include "includes/ketnoi.php";
	include "includes/header.php";
	?>
</head>
    <body> 
            <?php
			include "includes/narbar.php";
            $baitren_mottrang = 5;
			if (isset($_GET['id'])) {
				$id = $_GET['id'];
			}
            if (!isset($_GET['page'])) {
                $page = 1;
            } else {
                $page = $_GET['page'];
            }
            $sodu_lieu = mysqli_num_rows($conn->query("SELECT * FROM `jobs` WHERE branch_id = $id")) or die(mysql_error());
            $sotrang = $sodu_lieu / $baitren_mottrang;
            $huuha = $page * $baitren_mottrang;
			$result = $conn->query("SELECT jobs.id,jobs.created_at,branch.name as type_branch,locations.name as type_locations,users.email as type_users,jobs.title,jobs.content,salary,exp FROM users INNER JOIN (locations INNER JOIN (branch INNER JOIN jobs ON branch.id = jobs.branch_id) ON locations.id = jobs.location_id) ON users.id = jobs.user_id  WHERE jobs.branch_id = $id" ) or die(mysql_error());
                    
            
            
			
            ?>
			<div class="container">
			<div class="row">
				<div class="col-md-9 column">
				<?php while ($info = mysqli_fetch_array($result)) {
					echo '<div class="row clearfix">
						<div class="col-md-8 column">
						 <h3><a href="./chitiet.php?id='.$info['id'].'" >'.$info['title'].'</a></h3>
						<p>'.$info['salary'].' | '.$info['type_locations'].'</p>
						 <p>Ngày đăng: '.$info['created_at'].'</p>
						</div>
						<div class="col-md-2 column">
							Công Ty ABC
						</div>
						<div class="col-md-2 column">
							<a href="./chitiet.php?id='.$info['id'].'" class="btn btn-info">Chi tiết</a>
						</div>
					</div>
					<hr>';
					} ?>
				</div>			
			</div>
			<ul class="pagination">
			<?php for ($page = 1; $page <= $sotrang; $page ++) {
                echo "<li><a href='?page={$page}'>{$page}</a></li>";
            }?>		
			</ul>
		</div>
			<?php
                include "includes/footer.php";
                ?>
    </body>
</html>
